#ifndef CABAC_H
#define CABAC_H
#include "common.h"
#include "slice.h"

typedef struct
{
    /* state */
    int i_low;
    int i_range;

    /* bit stream */
    int i_queue; //stored with an offset of -8 for faster asm
    int i_bytes_outstanding;

    uint8_t *p_start;
    uint8_t *p;
    uint8_t *p_end;


    /* aligned for memcpy_aligned starting here */
    int f8_bits_encoded;    // only if using x264_cabac_size_decision()

    /* context */
    uint8_t state[1024];

    /* for 16-byte alignment */
    uint8_t padding[12];
} h264_cabac_t;

int h264_cabac_init(void);
void h264_cabac_context_init(h264_cabac_t *cabac_ctx, slice_type_e slice_type, int qp, int model);
void h264_cabac_encode_init(h264_cabac_t *cb, uint8_t *p_data, uint8_t *p_end);
int h264_cabac_pos(h264_cabac_t *cb);
void h264_cabac_encode_decision(h264_cabac_t *cb, int i_ctx, int b);
void x264_cabac_encode_terminal(h264_cabac_t *cb);
#endif